package com.zhiwang.planet.ui.main.v2

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.component.dly.xzzq_ywsdk.YwSDK
import com.component.dly.xzzq_ywsdk.YwSDK_WebActivity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.zhiwang.planet.App
import com.zhiwang.planet.R
import com.zhiwang.planet.aop.net.LoginRequired
import com.zhiwang.planet.ui.BaseFragment
import com.zhiwang.planet.util.TokenManager
import kotlinx.android.synthetic.main.fragment_task.*

class FastTaskFragment : BaseFragment() {

    companion object {
        fun newInstance(): FastTaskFragment {
            val args = Bundle()

            val fragment = FastTaskFragment()
            fragment.arguments = args
            return fragment
        }
    }


    var sdk: Boolean = false


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_task, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        tabLayout.setTabsWithTitles(arrayListOf("全部", "上新", "高额", "免审"), childFragmentManager, R.id.viewPager,
                arrayListOf(
                        ListFragment.newInstance("quanbu"),
                        ListFragment.newInstance("shangxin"),
                        ListFragment.newInstance("gaoe"),
                        ListFragment.newInstance("mianshen")
//                        ListFragment.newInstance("jisushenhe")

                ))

        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {

//                if (position == 4) {
//                    navFish()
//                    sdk = true
//                }
            }

            override fun onTabReselect(position: Int) {

            }

        })

    }


    @LoginRequired
    private fun navFish() {

        YwSDK.init(
                App.instance,
                "l1seq9x35hxol2qi644blibzh5qz4bng",
                "1306",
                TokenManager.webviewHeaderUserid(),
                "1",
                TokenManager.getDeviceId())
        YwSDK_WebActivity.open(App.instance)
    }

    val TAG = "FastTaskFragment"

    override fun onPause() {
        super.onPause()
        Log.i(TAG, "onPause: ")
    }


    override fun onStart() {
        super.onStart()
        if (sdk) {

            tabLayout.currentTab = 0
        }

    }

}